#SingleInstance, Force
SendMode Input
SetWorkingDir, %A_ScriptDir%
; web tool



Web(url, method:="GET", data:="") {
    if (data == "" || method == "GET") {
        Return Web_Get(url)
    }
    else {
        Return Web_Post(url, data)
    }
}



Web_Get(url) {
    request := ComObjCreate("WinHttp.WinHttpRequest.5.1")

    ; 'true', request.WaitForResponse() 允许脚本保持响应
    request.Open("GET", url, true)
    request.Send()
    request.WaitForResponse()

    Return request.ResponseText
}



; @TODO
Web_Post(url, data) {
    try{ ; only way to properly protect from an error here
        request := ComObjCreate("WinHttp.WinHttpRequest.5.1")
        request.Open("POST", url, true)
        request.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

        ; "username=" User "&password=" Pass
        request.Send(data)
        request.WaitForResponse()

        aMess := StrSplit(request.ResponseText, A_Space, """")
        MsgBox ,, %A_ScriptName% - Row %A_LineNumber%, % "POST request .: `n1) Result .: " aMess[1] "`n2) trackingid .: " aMess[2]
    } catch e {
        MsgBox 64, %A_ScriptName% - Row %A_LineNumber%, % e.message
        ; return e.message
    }
}
